package com.billManage.system.service.impl;

import java.util.Date;
import java.util.List;
import com.billManage.common.utils.DateUtils;
import com.billManage.system.domain.SysBillApplyRecord;
import com.billManage.system.domain.SysBillRecord;
import com.billManage.system.mapper.SysBillApplyRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.billManage.system.mapper.SysBillApplyMapper;
import com.billManage.system.domain.SysBillApply;
import com.billManage.system.service.ISysBillApplyService;
import com.billManage.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 票据报销申请Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-05-20
 */
@Service
public class SysBillApplyServiceImpl implements ISysBillApplyService 
{
    @Autowired
    private SysBillApplyMapper sysBillApplyMapper;
    @Autowired
    private SysBillApplyRecordMapper  sysBillApplyRecordMapper;

    /**
     * 查询票据报销申请
     * 
     * @param billRecordId 票据报销申请主键
     * @return 票据报销申请
     */
    @Override
    public SysBillApply selectSysBillApplyByBillRecordId(Long billRecordId)
    {
        return sysBillApplyMapper.selectSysBillApplyByBillRecordId(billRecordId);
    }

    /**
     * 查询票据报销申请列表
     * 
     * @param sysBillApply 票据报销申请
     * @return 票据报销申请
     */
    @Override
    public List<SysBillApply> selectSysBillApplyList(SysBillApply sysBillApply)
    {
        return sysBillApplyMapper.selectSysBillApplyList(sysBillApply);
    }

    /**
     * 新增票据报销申请
     * 
     * @param sysBillApply 票据报销申请
     * @return 结果
     */
    @Override
    public int insertSysBillApply(SysBillApply sysBillApply)
    {
        sysBillApply.setCreateTime(DateUtils.getNowDate());
        return sysBillApplyMapper.insertSysBillApply(sysBillApply);
    }

    /**
     * 修改票据报销申请
     * 
     * @param sysBillApply 票据报销申请
     * @return 结果
     */
    @Override
    public int updateSysBillApply(SysBillApply sysBillApply)
    {
        sysBillApply.setUpdateTime(DateUtils.getNowDate());
        return sysBillApplyMapper.updateSysBillApply(sysBillApply);
    }

    /**
     * 批量删除票据报销申请
     * 
     * @param billRecordIds 需要删除的票据报销申请主键
     * @return 结果
     */
    @Override
    public int deleteSysBillApplyByBillRecordIds(String billRecordIds)
    {
        return sysBillApplyMapper.deleteSysBillApplyByBillRecordIds(Convert.toStrArray(billRecordIds));
    }

    /**
     * 删除票据报销申请信息
     * 
     * @param billRecordId 票据报销申请主键
     * @return 结果
     */
    @Override
    public int deleteSysBillApplyByBillRecordId(Long billRecordId)
    {
        return sysBillApplyMapper.deleteSysBillApplyByBillRecordId(billRecordId);
    }

    @Override
    @Transactional
    public int updateSysBillApplyCw(SysBillApply sysBillApply) {
        //审核记录
        SysBillApplyRecord sysBillPpplyRecord = new SysBillApplyRecord();
        sysBillPpplyRecord.setBillId(sysBillApply.getBillId());
        sysBillPpplyRecord.setBillApplyId(sysBillApply.getBillApplyId());
        sysBillPpplyRecord.setReason(sysBillApply.getReason());
        sysBillPpplyRecord.setReviewBy(sysBillApply.getReviewBy());
        sysBillPpplyRecord.setReviewTime(sysBillApply.getReviewTime());
        sysBillPpplyRecord.setCreateBy(sysBillApply.getReviewBy());
        sysBillPpplyRecord.setCreateTime(new Date());
        this.sysBillApplyRecordMapper.insertSysBillApplyRecord(sysBillPpplyRecord);

        return sysBillApplyMapper.updateSysBillApply(sysBillApply);
    }
}
